<include file="./Application/Home/View/public/header.html"/>
<div class="ch-container">
    <div class="row">
        <!-- left menu starts -->
        <div class="col-sm-2 col-lg-2">
            <div class="sidebar-nav">
                <div class="nav-canvas">
                    <div class="nav-sm nav nav-stacked">

                    </div>
                    <ul class="nav nav-pills nav-stacked main-menu">
                        <li class="nav-header">功能</li>
                        <li><a class="ajax-link" href="{:U('poster')}"><i
                                class="glyphicon glyphicon-home"></i><span> 主页</span></a>
                        </li>
                        <li><a class="ajax-link" href="{:U('posterList')}"><i
                                    class="glyphicon glyphicon-align-justify"></i><span> 推送列表</span></a>
                        </li>
                        <li><a class="" href="{:U('newPoster')}"> <i
                                class="glyphicon glyphicon-plus-sign"></i><span> 新增推送</span></a>
                        </li>
                         <li><a class="ajax-link" href="{:U('galleryList')}"><i class="glyphicon glyphicon-picture"></i><span> 图片列表</span></a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <!--/span-->
        <!-- left menu ends -->

        <noscript>
            <div class="alert alert-block col-md-12">
                <h4 class="alert-heading">Warning!</h4>

                <p>You need to have <a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a>
                    enabled to use this site.</p>
            </div>
        </noscript>

        <div id="content" class="col-lg-10 col-sm-10">
            <!-- content starts -->
                <div>
        <ul class="breadcrumb">
            <li>
                <a href="#">Home</a>
            </li>
            <li>
                <a href="#">Tables</a>
            </li>
        </ul>
    </div>

    <div class="row">
    <div class="box col-md-12">
    <div class="box-inner">
    <div class="box-header well" data-original-title="">
        <h2><i class="glyphicon glyphicon-user"></i>推送列表</h2>
    </div>
    <div class="box-content">
        <a class="btn btn-danger" id="deleteAll" href="#"><i class="glyphicon glyphicon-trash"></i> 批量删除</a>
        <br/>
        <br/>
        <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
    <thead>
    <tr>
        <th><input type="checkbox" id="selectAll" name="selectAll"></th>
        <th>标题</th>
        <th>创建时间</th>
        <th>创建人</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <volist name="data" id="vo">
        <tr>
            <td><input type="checkbox" value="{$vo.post_id}" name="post_id"></td>
            <input type="hidden">
            <td>{$vo.post_title}</td>
            <td class="center">{$vo.create_time }</td>
            <td class="center">{$vo.create_by }</td>
            <td class="center">
                <if condition="$vo.status eq 1">
                    <span class="label-success label label-default">已启用</span>
                    <else />
                    <span class="label-default label label-danger">已禁用</span>
                </if>
            </td>
            <td class="center">
                <a class="btn btn-success" href="{:U('Index/posterPreview',array('post_id'=>$vo['post_id']))}">
                    <i class="glyphicon glyphicon-zoom-in icon-white"></i>
                    预览
                </a>
                <a class="btn btn-info" href="{:U('posterEdit',array('post_id'=>$vo['post_id']))}">
                    <i class="glyphicon glyphicon-edit icon-white"></i>
                    编辑
                </a>
                <a class="btn btn-danger deleteOne" href="javascript:void(0);" ajax-href="{:U('posterDelete')}">
                    <i class="glyphicon glyphicon-trash icon-white"></i>
                    删除
                </a>
            </td>
        </tr>
    </volist>
    </tbody>
    </table>
        <!--提示信息-->
    <button class="btn btn-primary noty" id="noty_success" style="display: none;"
            data-noty-options="{&quot;text&quot;:&quot;删除成功&quot;,&quot;layout&quot;:&quot;top&quot;,&quot;type&quot;:&quot;success&quot;,&quot;closeButton&quot;:&quot;true&quot;}">
        <i class="glyphicon glyphicon-bell icon-white"></i> Bottom Full Width with Close Button
    </button>
    <button class="btn btn-primary noty" id="noty_error" style="display: none;"
            data-noty-options="{&quot;text&quot;:&quot;删除失败！&quot;,&quot;layout&quot;:&quot;top&quot;,&quot;type&quot;:&quot;error&quot;,&quot;animateOpen&quot;: {&quot;opacity&quot;: &quot;show&quot;}}">
        <i class="glyphicon glyphicon-bell icon-white"></i> Center (fade)
    </button>
    <!--提示信息完-->
    </div>
    </div>
    </div>
    <!--/span-->
    </div><!--/row-->
    <!-- content ends -->
    </div><!--/#content.col-md-0-->
</div><!--/fluid-row-->
<include file="./Application/Home/View/public/footer.html"/>
    <script>
        $("#selectAll").on('change',function(){
            $(this).parents("table").find("tbody input[name=post_id]").prop("checked", $(this).prop("checked"));
        });
        $("#deleteAll").on("click",function(){
            var idStr='';
            var _this= $(this);
            $(".table").find("input[name=post_id]:checked").each(function(){
                idStr+=$(this).val()+',';
            });
            idStr = idStr.substring(0,idStr.length-1);
            $.ajax({ url:"{:U('posterDelete')}" , data: {idStr:idStr}, type: "post", dataType: "json", cache: false, async: true,
                success: function(data){
                    if(!!data && data.status){
                        $("#noty_success").click();
                        _this.parents("tr").remove();
                    }else{
                        $("#noty_error").click();
                    }
                },
                error: function (XMLresponseText){
                    alert(XMLresponseText);
                }
            });
        })
        $(".deleteOne").on("click",function(){
            var _this= $(this);
            $.ajax({ url:$(this).attr("ajax-href"),data:{idStr:$(this).parents('tr').find("input[name=post_id]").val()}, type: "post", dataType: "json", cache: false, async: true,
                success: function(data){
                    if(!!data && data.status){
                        $.IvanDialogOpen({
                            Type: 'tips',
                            Info: "删除数据成功",
                            Plugins: { CloseTime: 1200,CloseFun:true},
                            FunOk: function () {
                               window.location.reload(true);
                            }
                        });
                    }else{
                        $.IvanDialogOpen({
                            Type: 'tips',
                            Info: "删除失败",
                            Plugins: { CloseTime: 1200 }
                        });
                    }
                },
                error: function (XMLresponseText){
                    alert(XMLresponseText);
                }
            });
        })
    </script>